<?php
namespace api\modules\v1\controllers;

use Yii;
use api\components\ApiController;
use api\modules\v1\models\Coin;

/**
 * 虚拟币控制器
 * @author CGA
 */
class CoinController extends ApiController
{
    /**
     * 添加虚拟币
     * @author CGA
     */
    public function actionCoinAdd()
    {
        $params = Yii::$app->request->post();
        $model = new Coin();
        $model->setScenario(Coin::SCENARIO_TYPE_ADD);
        $model->load($params, '');
        if ($result = $model->coinAdd()) {
            return ['message' => '添加成功', 'data' => $result];
        }
    }

    /**
     * 虚拟币列表
     * @author CGA
     */
    public function actionCoinList()
    {
        $result = Coin::getCoinList();
        return ['message' => '获取成功', 'data' => $result];
    }

    /**
     * 添加法币
     * @author CGA
     */
    public function actionCurrencyAdd()
    {
        $params = Yii::$app->request->post();
        $model = new Coin();
        $model->setScenario(Coin::SCENARIO_TYPE_ADD);
        $model->load($params, '');
        if ($result = $model->currencyAdd()) {
            return ['message' => '添加成功', 'data' => $result];
        }
    }

    /**
     * 法币列表
     * @author CGA
     */
    public function actionCurrencyList()
    {
        $result = Coin::getCurrencyList();
        return ['message' => '获取成功', 'data' => $result];
    }

    /**
     * 提款
     * @author CGA
     */
    public function actionWithdrawals()
    {
        $params = Yii::$app->request->post();
        $model = new Coin();
        $model->setScenario(Coin::SCENARIO_WITHDRAWALS);
        $model->load($params, '');
        if ($result = $model->coinWithdrawal()) {
            return ['message' => '提款成功'];
        }
    }
}
